﻿<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>admin</title>
        <link type="text/css" rel="stylesheet" media="all" href="<%=request.getContextPath()%>/styles/global.css"/>
        <link type="text/css" rel="stylesheet" media="all" href="<%=request.getContextPath()%>/styles/global_color.css"/>
        <script src="/styles/jquery-3.3.1.js"></script>
        <script language="javascript" type="text/javascript">
            //保存成功的提示消息
            function showResult() {
                showResultDiv(true);
                window.setTimeout("showResultDiv(false);", 3000);
            }
            function showResultDiv(flag) {
                var divResult = document.getElementById("save_result_info");
                if (flag)
                    divResult.style.display = "block";
                else
                    divResult.style.display = "none";
            }



            $(function () {
                $.ajax({
                    type: "POST",
                    url: "/admin.do/queryRoleInfo",

                    success: function (resp) {
                        var div = $('#div234');
                        var ul = $('<ul></ul>')

                        for (const item of resp) {
                            var li = $('<li></li>').text(item.name);
                            // li.name="roleId";
                            // li.type="checkbox";
                            var input = $("<input type='checkbox' name='roleId'/>")
                            input.attr("value",item.roleId);

                            li.append(input);
                            ul.append(li);
                        }
                        div.append(ul)
                    }

                })
            })

        </script>
    </head>
    <body>
        <!--Logo区域开始-->
        <div id="header">
            <img src="../images/logo.png" alt="logo" class="left"/>
            <a href="<%=request.getContextPath()%>/admins/exit">[退出]</a>
        </div>
        <!--Logo区域结束-->
        <!--导航区域开始-->
        <div id="navi">
            <c:import url="../navigation.jsp"/>
            <script>
                var li = document.getElementById("menu").children;
                var title = document.getElementsByTagName('title')[0].textContent;
                for (let i = 0; i < li.length; i++) {
                    if (li[i].children[0].className.startsWith(title)){
                        li[i].children[0].className = title + '_on';
                    }
                }
            </script>
        </div>
        <!--导航区域结束-->
        <!--主要区域开始-->
        <script>

            function verifyNameBlur() {
                const regtitle = /^[A-Za-z0-9]{0,20}$/;
                const uname = $("#name").val();
                if (uname.length <= 0 || !regtitle.test(uname)) {
                    $("#verifyNameError").show();
                } else {
                    $("#verifyNameError").hide();
                }
            }

            function verifyTelephoneBlur() {
                // const regtitle = /^(13[0-9]|15[0-9]|18[0-9]|16[0-9])\d{8}$/;
                const regtitle = /^1[0-9]{10}$/;
                const telephone = $("#telephone").val();
                if (telephone.length <= 0 || !regtitle.test(telephone)) {
                    $("#verifyTelephoneError").show();
                } else {
                    $("#verifyTelephoneError").hide();
                }
            }

            function verifyEmailBlur() {
                const regtitle = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
                const email = $("#email").val();
                if (email.length <= 0 || !regtitle.test(email)) {
                    $("#verifyEmailError").show();
                } else {
                    $("#verifyEmailError").hide();
                }
            }


            function checkTech() {
                // var techNode = document.getElementsByName("roleId");
                // var flag = false;
                var checked=$("input[name='roleId']:checked");
                if(checked.length==0){
                    $('#verifyRoleError').show();
                }else {
                    $('#verifyRoleError').hide();
                }
            }

        </script>

        <div id="main">
            <div id="save_result_info" class="save_success">保存成功！</div>
            <form action="<%=request.getContextPath()%>/admin.do/updateAdminData" method="post" class="main_form">
                    <div class="text_info clearfix"><span>姓名：</span></div>
                    <div class="input_info">
                        <input onblur="verifyNameBlur()" name="name" id="name" type="text" value="${adminInfo.name}"/> <span class="required">*</span>
                        <span style="display: none" id="verifyNameError" class="validate_msg_long error_msg">20长度以内的汉字、字母、数字的组合</span>
                    </div>
                    <div class="text_info clearfix"><span>管理员账号：</span></div>
                    <div class="input_info"><input name="adminCode" value="${adminInfo.adminCode}" id="adminCode" type="text" readonly="readonly" class="readonly"   /></div>
                    <div class="text_info clearfix"><span>电话：</span></div>
                    <div class="input_info">
                        <input onblur="verifyTelephoneBlur()" name="telephone" value="${adminInfo.telephone}" id="telephone" type="text"   />
                        <span class="required">*</span>
                        <span style="display: none" id="verifyTelephoneError" class="validate_msg_long error_msg">正确的电话号码格式：手机或固话</span>
                    </div>
                    <div class="text_info clearfix"><span>Email：</span></div>
                    <div class="input_info">
                        <input onblur="verifyEmailBlur()"  name="email" value="${adminInfo.email}" id="email" type="text" class="width200" />
                        <span class="required">*</span>
                        <span style="display: none" id="verifyEmailError" class="validate_msg_medium error_msg">50长度以内，正确的 email 格式</span>
                    </div>

                <input name="adminId" type="hidden" value="${adminInfo.adminId}"/>
                <%--写个隐藏的input标签 携带参数同表单一起传到controller--%>
                    <div class="text_info clearfix"><span>角色：</span></div>
                    <div class="input_info_high">
                        <div onmouseover="checkTech()" id="div234" class="input_info_scroll">
                            <ul>
                                <%--<li><input type="checkbox" />超级管理员</li>--%>
                                <%--<li><input type="checkbox" />账务账号管理员</li>--%>
                                <%--<li><input type="checkbox" />业务账号管理员</li>--%>
                                <%--<li><input type="checkbox" />账务账号管理员</li>--%>
                                <%--<li><input type="checkbox" />业务账号管理员</li>--%>
                                <%--<li><input type="checkbox" />账务账号管理员</li>--%>
                                <%--<li><input type="checkbox" />业务账号管理员</li>--%>
                            </ul>
                        </div>
                        <span class="required">*</span>
                        <div style="display: none" id="verifyRoleError" class="validate_msg_tiny error_msg">至少选择一个</div>
                    </div>
                    <div class="button_info clearfix">
                        <input type="submit" value="保存" class="btn_save" />
                        <input type="button" value="取消" class="btn_save" onclick="window.location.href='/admin.do/findAll'" />
                    </div>
                </form>
        </div>
        <!--主要区域结束-->
        <div id="footer">
            <span>[源自北美的技术，最优秀的师资，最真实的企业环境，最适用的实战项目]</span>
            <br />
            <span>版权所有(C)云科技有限公司 </span>
        </div>
    </body>
</html>
